package com.noshufou.android.su;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SectionIndexer;
import android.widget.TextView;
import com.noshufou.android.su.provider.PermissionsProvider.Apps;
import com.noshufou.android.su.provider.PermissionsProvider.Logs;
import com.noshufou.android.su.service.ResultService;
import com.noshufou.android.su.util.Util;
import com.noshufou.android.su.widget.AppListItem;
import com.noshufou.android.su.widget.PinnedHeaderListView;
import com.noshufou.android.su.widget.PinnedHeaderListView.PinnedHeaderAdapter;
import com.noshufou.android.su.widget.PinnedHeaderListView.PinnedHeaderCache;
import java.util.HashMap;

public class AppListFragment extends ListFragment
  implements LoaderManager.LoaderCallbacks<Cursor>
{
  private static final int COLUMN_ALLOW = 3;
  private static final int COLUMN_ID = 0;
  private static final int COLUMN_LAST_ACCESS = 4;
  private static final int COLUMN_LAST_ACCESS_TYPE = 5;
  private static final int COLUMN_NAME = 2;
  private static final int COLUMN_UID = 1;
  public static final String[] PROJECTION;
  private static final String TAG = "Su.AppListFragment";
  private AppListAdapter mAdapter;
  private LinearLayout mLoadingLayout = null;
  private int mPinnedHeaderBackgroundColor;
  private boolean mShowLogData = true;
  private boolean mShowStatusIcons = true;
  private String mStatusIconType = null;

  static
  {
    String[] arrayOfString = new String[6];
    arrayOfString[0] = "_id";
    arrayOfString[1] = "uid";
    arrayOfString[2] = "name";
    arrayOfString[3] = "allow";
    arrayOfString[4] = "date";
    arrayOfString[5] = "type";
    PROJECTION = arrayOfString;
  }

  private void doToggle(long paramLong, int paramInt)
  {
    int i = 1;
    ContentResolver localContentResolver = getActivity().getContentResolver();
    Uri localUri = Uri.withAppendedPath(PermissionsProvider.Apps.CONTENT_URI, String.valueOf(paramLong));
    ContentValues localContentValues = new ContentValues();
    if (paramInt == i)
      i = 0;
    localContentValues.put("allow", Integer.valueOf(i));
    localContentResolver.update(localUri, localContentValues, null, null);
    localContentValues.clear();
    localContentValues.put("date", Long.valueOf(System.currentTimeMillis()));
    localContentValues.put("type", Integer.valueOf(3));
    localContentResolver.insert(Uri.withAppendedPath(PermissionsProvider.Logs.CONTENT_URI, String.valueOf(paramLong)), localContentValues);
    Intent localIntent = new Intent(getActivity(), ResultService.class);
    localIntent.putExtra("action", 2);
    getActivity().startService(localIntent);
  }

  private void setupListView()
  {
    ListView localListView = getListView();
    LayoutInflater localLayoutInflater = getActivity().getLayoutInflater();
    localListView.setDividerHeight(0);
    this.mAdapter = new AppListAdapter(null, getActivity());
    setListAdapter(this.mAdapter);
    if (((localListView instanceof PinnedHeaderListView)) && (this.mAdapter.getDisplaySectionHeadersEnabled()))
    {
      this.mPinnedHeaderBackgroundColor = -1;
      ((PinnedHeaderListView)localListView).setPinnedHeaderView(localLayoutInflater.inflate(2130903054, localListView, false));
    }
    localListView.setOnScrollListener(this.mAdapter);
  }

  public void onActivityCreated(Bundle paramBundle)
  {
    super.onActivityCreated(paramBundle);
    setupListView();
    getLoaderManager().initLoader(0, null, this);
  }

  public Loader<Cursor> onCreateLoader(int paramInt, Bundle paramBundle)
  {
    FragmentActivity localFragmentActivity = getActivity();
    Uri localUri = PermissionsProvider.Apps.CONTENT_URI;
    String[] arrayOfString1 = PROJECTION;
    String[] arrayOfString2 = new String[1];
    arrayOfString2[0] = String.valueOf(-1);
    return new CursorLoader(localFragmentActivity, localUri, arrayOfString1, "allow!=?", arrayOfString2, null);
  }

  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    View localView = paramLayoutInflater.inflate(2130903051, paramViewGroup, false);
    this.mLoadingLayout = ((LinearLayout)localView.findViewById(2131361842));
    return localView;
  }

  public void onListItemClick(ListView paramListView, View paramView, int paramInt, long paramLong)
  {
    ((HomeActivity)getActivity()).showDetails(paramLong);
  }

  public void onLoadFinished(Loader<Cursor> paramLoader, Cursor paramCursor)
  {
    this.mAdapter.swapCursor(paramCursor);
    this.mLoadingLayout.setVisibility(8);
    HomeActivity localHomeActivity = (HomeActivity)getActivity();
    Fragment localFragment = localHomeActivity.getSupportFragmentManager().findFragmentById(2131361801);
    boolean bool = PreferenceManager.getDefaultSharedPreferences(localHomeActivity).getBoolean("pref_logging", true);
    long l;
    if ((localFragment instanceof AppDetailsFragment))
    {
      l = 0L;
      if (!bool)
        break label100;
      l = ((AppDetailsFragment)localFragment).getShownIndex();
    }
    while (true)
    {
      getListView().setItemChecked(this.mAdapter.getPositionForId(l), true);
      return;
      label100: if ((paramCursor == null) || (!paramCursor.moveToFirst()))
        continue;
      l = paramCursor.getLong(0);
      ((AppDetailsFragment)localFragment).setShownIndex(l);
    }
  }

  public void onLoaderReset(Loader<Cursor> paramLoader)
  {
    this.mAdapter.swapCursor(null);
  }

  public void onResume()
  {
    super.onResume();
    int i = 0;
    SharedPreferences localSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    boolean bool1 = localSharedPreferences.getBoolean("pref_show_status_icons", true);
    if (this.mShowStatusIcons != bool1)
      i = 1;
    this.mShowStatusIcons = bool1;
    boolean bool2 = localSharedPreferences.getBoolean("pref_applist_show_log_data", true);
    if (this.mShowLogData != bool2)
      i = 1;
    this.mShowLogData = bool2;
    String str = localSharedPreferences.getString("pref_status_icon_type", "emote");
    if (this.mStatusIconType == null)
      i = 0;
    while (true)
    {
      this.mStatusIconType = str;
      if (i != 0)
        getLoaderManager().restartLoader(0, null, this);
      return;
      if (str.equals(this.mStatusIconType))
        continue;
      i = 1;
    }
  }

  public class AppListAdapter extends CursorAdapter
    implements AbsListView.OnScrollListener, SectionIndexer, PinnedHeaderListView.PinnedHeaderAdapter
  {
    private Cursor mCursor;
    private boolean mDisplaySectionHeaders;
    private int mLastCachedPosition;
    private HashMap<Long, Integer> mPositions;
    private int[] mSectionPositions;
    private final int[] mSectionTypes;
    private final String[] mSections;

    public AppListAdapter(Cursor paramContext, Context arg3)
    {
      super(paramContext, false);
      String[] arrayOfString = new String[2];
      arrayOfString[i] = AppListFragment.this.getString(2131427353);
      arrayOfString[1] = AppListFragment.this.getString(2131427355);
      this.mSections = arrayOfString;
      int[] arrayOfInt1 = new int[2];
      arrayOfInt1[i] = 1;
      this.mSectionTypes = arrayOfInt1;
      int[] arrayOfInt2 = new int[2];
      arrayOfInt2[1] = -1;
      this.mSectionPositions = arrayOfInt2;
      this.mDisplaySectionHeaders = true;
      this.mLastCachedPosition = -1;
      if (paramContext != null)
        i = paramContext.getCount();
      this.mPositions = new HashMap(i);
      this.mLastCachedPosition = -1;
      this.mCursor = paramContext;
    }

    private void bindSectionHeader(View paramView, int paramInt, boolean paramBoolean)
    {
      AppListItem localAppListItem = (AppListItem)paramView;
      if (!paramBoolean)
      {
        localAppListItem.setSectionHeader(null);
        localAppListItem.setDividerVisible(true);
      }
      while (true)
      {
        return;
        int i = getSectionForPosition(paramInt);
        if (getPositionForSection(i) == paramInt)
          localAppListItem.setSectionHeader(this.mSections[i]);
        while (true)
        {
          if (-1 + getPositionForSection(i + 1) != paramInt)
            break label91;
          localAppListItem.setDividerVisible(true);
          break;
          localAppListItem.setDividerVisible(false);
          localAppListItem.setSectionHeader(null);
        }
        label91: localAppListItem.setDividerVisible(true);
      }
    }

    public void bindView(View paramView, Context paramContext, Cursor paramCursor)
    {
      AppListItem localAppListItem = (AppListItem)paramView;
      paramCursor.getLong(0);
      int i = paramCursor.getInt(1);
      String str = paramCursor.getString(2);
      int j = paramCursor.getInt(3);
      localAppListItem.setAppIcon(Util.getAppIcon(AppListFragment.this.getActivity(), i));
      label107: int m;
      if ((str != null) && (str.length() > 0))
      {
        localAppListItem.setNameText(str);
        if (!AppListFragment.this.mShowStatusIcons)
          break label256;
        localAppListItem.setStatusButton(Util.getStatusIconDrawable(AppListFragment.this.getActivity(), j), 0, 0L);
        long l = paramCursor.getLong(4);
        if ((!AppListFragment.this.mShowLogData) || (l <= 0L))
          break label295;
        int k = paramCursor.getInt(5);
        m = 2131427368;
        switch (k)
        {
        default:
          label180: AppListFragment localAppListFragment = AppListFragment.this;
          Object[] arrayOfObject = new Object[2];
          arrayOfObject[0] = Util.formatDate(AppListFragment.this.getActivity(), l);
          arrayOfObject[1] = Util.formatTime(AppListFragment.this.getActivity(), l);
          localAppListItem.setLogText(localAppListFragment.getString(m, arrayOfObject));
        case 1:
        case 0:
        case 3:
        case 2:
        }
      }
      while (true)
      {
        return;
        localAppListItem.setNameText(AppListFragment.this.getString(2131427360));
        break;
        label256: localAppListItem.setStatusButton(null, 0, 0L);
        break label107;
        m = 2131427369;
        break label180;
        m = 2131427370;
        break label180;
        m = 2131427371;
        break label180;
        m = 2131427372;
        break label180;
        label295: localAppListItem.setLogText(null);
      }
    }

    public void configurePinnedHeader(View paramView, int paramInt1, int paramInt2)
    {
      PinnedHeaderListView.PinnedHeaderCache localPinnedHeaderCache = (PinnedHeaderListView.PinnedHeaderCache)paramView.getTag();
      if (localPinnedHeaderCache == null)
      {
        localPinnedHeaderCache = new PinnedHeaderListView.PinnedHeaderCache();
        localPinnedHeaderCache.titleView = ((TextView)paramView.findViewById(2131361847));
        localPinnedHeaderCache.textColor = localPinnedHeaderCache.titleView.getTextColors();
        localPinnedHeaderCache.background = paramView.getBackground();
        paramView.setTag(localPinnedHeaderCache);
      }
      int i = getSectionForPosition(paramInt1);
      String str = this.mSections[i];
      localPinnedHeaderCache.titleView.setText(str);
      if (paramInt2 == 255)
      {
        paramView.setBackgroundDrawable(localPinnedHeaderCache.background);
        localPinnedHeaderCache.titleView.setTextColor(localPinnedHeaderCache.textColor);
      }
      while (true)
      {
        return;
        int j = Color.red(AppListFragment.this.mPinnedHeaderBackgroundColor);
        int k = Color.green(AppListFragment.this.mPinnedHeaderBackgroundColor);
        int m = Color.blue(AppListFragment.this.mPinnedHeaderBackgroundColor);
        paramView.setBackgroundColor(Color.rgb(255 - paramInt2 * (255 - j) / 255, 255 - paramInt2 * (255 - k) / 255, 255 - paramInt2 * (255 - m) / 255));
        int n = localPinnedHeaderCache.textColor.getDefaultColor();
        localPinnedHeaderCache.titleView.setTextColor(Color.argb(paramInt2, Color.red(n), Color.green(n), Color.blue(n)));
      }
    }

    public boolean getDisplaySectionHeadersEnabled()
    {
      return this.mDisplaySectionHeaders;
    }

    public int getPinnedHeaderState(int paramInt)
    {
      int i = 0;
      if ((this.mCursor == null) || (this.mCursor.getCount() == 0) || (this.mCursor.isClosed()));
      while (true)
      {
        return i;
        if (paramInt < 0)
          continue;
        int j = getPositionForSection(1 + getSectionForPosition(paramInt));
        if ((j != -1) && (paramInt == j - 1))
        {
          i = 2;
          continue;
        }
        i = 1;
      }
    }

    public int getPositionForId(long paramLong)
    {
      int i;
      if (this.mPositions.containsKey(Long.valueOf(paramLong)))
        i = ((Integer)this.mPositions.get(Long.valueOf(paramLong))).intValue();
      while (true)
      {
        return i;
        this.mCursor.moveToPosition(this.mLastCachedPosition);
        do
        {
          if (!this.mCursor.moveToNext())
          {
            i = -1;
            break;
          }
          this.mLastCachedPosition = (1 + this.mLastCachedPosition);
        }
        while (this.mCursor.getLong(0) != paramLong);
        this.mPositions.put(Long.valueOf(paramLong), Integer.valueOf(this.mLastCachedPosition));
        i = this.mLastCachedPosition;
      }
    }

    public int getPositionForSection(int paramInt)
    {
      if (paramInt > 1);
      for (int i = this.mCursor.getCount(); ; i = this.mSectionPositions[paramInt])
      {
        return i;
        if (this.mSectionPositions[paramInt] <= -1)
          break;
      }
      Uri localUri = Uri.withAppendedPath(PermissionsProvider.Apps.COUNT_CONTENT_URI, String.valueOf(this.mSectionTypes[(paramInt - 1)]));
      Cursor localCursor = AppListFragment.this.getActivity().getContentResolver().query(localUri, null, null, null, null);
      if (localCursor.moveToFirst());
      for (i = localCursor.getInt(0); ; i = 0)
      {
        localCursor.close();
        this.mSectionPositions[paramInt] = i;
        break;
      }
    }

    public int getSectionForPosition(int paramInt)
    {
      int i = 1;
      if (this.mCursor == null)
        i = -1;
      while (true)
      {
        return i;
        this.mCursor.moveToPosition(paramInt);
        if (this.mCursor.getInt(3) != i)
          continue;
        i = 0;
      }
    }

    public Object[] getSections()
    {
      return this.mSections;
    }

    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      View localView = super.getView(paramInt, paramView, paramViewGroup);
      bindSectionHeader(localView, paramInt, true);
      return localView;
    }

    public boolean hasStableIds()
    {
      return true;
    }

    public View newView(Context paramContext, Cursor paramCursor, ViewGroup paramViewGroup)
    {
      return new AppListItem(paramContext, null);
    }

    public void onScroll(AbsListView paramAbsListView, int paramInt1, int paramInt2, int paramInt3)
    {
      if (((paramAbsListView instanceof PinnedHeaderListView)) && (paramInt2 > 0))
        ((PinnedHeaderListView)paramAbsListView).configureHeaderView(paramInt1);
    }

    public void onScrollStateChanged(AbsListView paramAbsListView, int paramInt)
    {
    }

    public Cursor swapCursor(Cursor paramCursor)
    {
      this.mSectionPositions[1] = -1;
      this.mCursor = paramCursor;
      if (paramCursor != null);
      for (int i = paramCursor.getCount(); ; i = 0)
      {
        this.mPositions = new HashMap(i);
        this.mLastCachedPosition = -1;
        return super.swapCursor(paramCursor);
      }
    }
  }
}

/* Location:           D:\Development\Decompile_Workspace\슈퍼유저-41\classes_dex2jar.jar
 * Qualified Name:     com.noshufou.android.su.AppListFragment
 * JD-Core Version:    0.6.0
 */